const {ipcMain} = require('electron')
const fs= require('fs')
const myinfo = require("./myinfo")
const createSqlite = require("./createSqlite")
const Windows = require("../main.js")
module.exports = {
    info: function(){
        //监听web page里发出的message
        //拿到用户名片，根据IM账号判断当前账号存不存在数据库
        ipcMain.on('electron-onMyInfo', (event, arg) => {
            myinfo.my = arg;
            fs.exists("./sqlite/"+arg.account+".sqlite",function(msg){
                createSqlite.createDB(msg)
            })
        })
        //收到消息
        ipcMain.on('electron-onMsg', (event, arg) => {
            var msg = createSqlite.writeToOnMsg(arg);
            Windows.webContents.send("sendOnMsg",msg)
        })
        //收到离线消息
        ipcMain.on('electron-onOfflineMsgs', (event, arg) => {
            createSqlite.writeToOnMsg(arg);
        })




    }
}